<template>
  <div class="tab-control">
    <div class="tab-item" v-for="(item, index) in titles" :key="index">
      <span
        @click="toggleTitle(index)"
        :class="{ active: currentIndex === index }"
        >{{ item }}</span
      >
    </div>
  </div>
</template>

<script>
export default {
  props: {
    titles: Array
  },
  components: {},
  data() {
    return {
      currentIndex: 0
    }
  },
  methods: {
    toggleTitle(index) {
      this.currentIndex = index
      this.$emit('tabToggle', index)
    }
  }
}
</script>

<style lang="less" scoped>
.tab-control {
  display: flex;
  text-align: center;
}

.tab-item {
  flex: 1;
  height: 40px;
  line-height: 40px;
}

.tab-item span {
  padding: 5px;
}

span.active {
  color: var(--color-a);
  border-bottom: 2px solid var(--color-a);
}
</style>
